"""
This module provides a function to read binary files in chunks.
"""
def reader_bin(file_path, pattern: int = 4,size: int = 0):
    """
    打开二进制文件，逐个读取pattern字节，返回原始字节串
    Args:
        file_path (str): 二进制文件路径
        pattern: 一次性读取的字节数 (默认 4 字节)
        size: 读取文件的次数
    Yields:
        读取的文件值
    """
    count = 0
    with open(file_path, "rb") as f:
        while True:
            chunk = f.read(pattern)
            if len(chunk) < pattern or size != 0 and count >= size:  # 文件末尾，不足 pattern 字节，停止迭代
                break
            yield chunk
        count += 1
